<?php

namespace app\api\controller;

use app\common\controller\Api;
use Payment\Client\Charge;
/**
 * 首页接口.
 */
class Pay extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页.
     */
    public function index()
    {
        $this->success('请求成功');
    }
    
    public function ali(){
            $config = [
            'use_sandbox' => false, // 是否使用沙盒模式
        
            'app_id'    => '2021001144613411',
            'sign_type' => 'RSA2', // RSA  RSA2
        
        
            // 支付宝公钥字符串
            'ali_public_key' => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmfW7vg4fJTMeOHj3wHxSMqte662SYMy5Nrdx2N/QhcUaGxWWkeAlF/GshSN65mVcf7rM5SXo1XHDHzEwTEbRuQgprGncp+ZKCuLyegv8oVhmLX7gdlU3wx922GyNftv1gvRnWiVFOLIPS5yO8mc6N1niC874kO3mZyWTrO4h8OO1zmujWyv8uecVLO5niThiN2PX1K3WY7xt8VKGiuVHBrVg9OAyBacraKVYRY8Yz1BfaIgw8vzwhnyFyMwMBOoaYomPw1PSaVPX3hE68znRHUNhJarAS7jH682lVU/uOXjLfKB3FkK4O3Lew0gWgLoLgoHc1AUAxoY+bAyXOKyx/wIDAQAB',
        
            // 自己生成的密钥字符串
            'rsa_private_key' => 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCI4rZFstZqhlSujSt93Il62PyeKIgGhfciz+ia0G5RImZWWueCmQkkAxC/qEesWKm/aRfBxT97Ympdhlg4qwPRZSCqAkCMN7foTbefNeTny7Kc1QM8M7DxDavYzvCEjsrWriBT8HBtlT7IYzXbpsd+7VLq4V4TN40KVTouMPDsf211tnXotKbGKgnbVSqiiGBsxjpMFxlARUK9uV8vE8dotWUhJZmxc3LzsoXmfix6PbDubF7J05j6qxgvkoT8HG9fpRmnDg8kFFO2RKSdpZF0IpVC6lLOjFZZmn+x1RG6ohIvE7Iu8DVV+R9fiPW+ByGriuQ3luP7IEXqJSzNwnedAgMBA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Z8X+8mRibjBpmWLI+vPup40C5hkXjGTyIWiiu+6lM+/mUho5QU7m3rMM8vndH7HATTwNhPrO2LKl8vLWD6OS2Bs1gxtiCXFvZ4uLjBLLWtvlVZGQV3Y05AB6KUW/bxdHq3Q9PGhYoqyZ2+SU=',
        
            'limit_pay' => [
                //'balance',// 余额
                //'moneyFund',// 余额宝
                //'debitCardExpress',// 	借记卡快捷
                //'creditCard',//信用卡
                //'creditCardExpress',// 信用卡快捷
                //'creditCardCartoon',//信用卡卡通
                //'credit_group',// 信用支付类型（包含信用卡卡通、信用卡快捷、花呗、花呗分期）
            ], // 用户不可用指定渠道支付当有多个渠道时用“,”分隔
        
            // 与业务相关参数
            'notify_url' => 'http://39.101.192.177/api/alindex/alipaynotifyurl',
            'return_url' => 'http://39.101.192.177/index/index/filish',
        ];
        $payData = [
            'body'         => '测试',
            'subject'      => '测试',
            'trade_no'     => 'test' . mt_rand(10000000,99999999),// 自己实现生成
            'time_expire'  => time() + 600, // 表示必须 600s 内付款
            'amount'       => 0.01, // 微信沙箱模式，需要金额固定为3.01
            'return_param' => '123',
            'client_ip'    => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1', // 客户地址
        ];
        $channel = 'ali_wap';
        $client = new \Payment\Client(\Payment\Client::WECHAT, $config);
        // $client = new \Payment\Client(\Payment\Client::ALI_CHANNEL_WAP, $wxConfig);
        $res    = $client->pay(\Payment\Client::ALI_CHANNEL_WAP, $payData);
         dd($res);
    }
    public function notifyurl(){
        // 实例支付对象
        $config = [
            // 微信支付参数
            'wechat' => [
                'app_id'     => '', // 应用ID
                'mch_id'     => '', // 微信支付商户号
                'mch_key'    => '', // 微信支付密钥
                'ssl_cer'    => '', // 微信证书 cert 文件
                'ssl_key'    => '', // 微信证书 key 文件
                'notify_url' => '', // 支付通知URL
            ],
            // 支付宝支付参数
            'alipay' => [
                'app_id'      => '2021001144613411', // 应用ID
                'public_key'  => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmfW7vg4fJTMeOHj3wHxSMqte662SYMy5Nrdx2N/QhcUaGxWWkeAlF/GshSN65mVcf7rM5SXo1XHDHzEwTEbRuQgprGncp+ZKCuLyegv8oVhmLX7gdlU3wx922GyNftv1gvRnWiVFOLIPS5yO8mc6N1niC874kO3mZyWTrO4h8OO1zmujWyv8uecVLO5niThiN2PX1K3WY7xt8VKGiuVHBrVg9OAyBacraKVYRY8Yz1BfaIgw8vzwhnyFyMwMBOoaYomPw1PSaVPX3hE68znRHUNhJarAS7jH682lVU/uOXjLfKB3FkK4O3Lew0gWgLoLgoHc1AUAxoY+bAyXOKyx/wIDAQAB', // 支付宝公钥(1行填写)
                'private_key' => 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCI4rZFstZqhlSujSt93Il62PyeKIgGhfciz+ia0G5RImZWWueCmQkkAxC/qEesWKm/aRfBxT97Ympdhlg4qwPRZSCqAkCMN7foTbefNeTny7Kc1QM8M7DxDavYzvCEjsrWriBT8HBtlT7IYzXbpsd+7VLq4V4TN40KVTouMPDsf211tnXotKbGKgnbVSqiiGBsxjpMFxlARUK9uV8vE8dotWUhJZmxc3LzsoXmfix6PbDubF7J05j6qxgvkoT8HG9fpRmnDg8kFFO2RKSdpZF0IpVC6lLOjFZZmn+x1RG6ohIvE7Iu8DVV+R9fiPW+ByGriuQ3luP7IEXqJSzNwnedAgMBAAECggEAFvX4Xw6Ver7Xm4PghLcmdG3LSfhAgN+dycAYI0fNCVz8z4VmCfkDmH/PImbmxtkEeC/3pTAh6t9iOhfb2n2NIWWWKg5Ap4R9G8FViKYwpFT9u+LbLRD6oCSL680ieQm+qm4AzDOrmCYNpu1FTnfWRMsoOm/dKNoLlW0gWjkpYHHsp1hVDmw14CM3BqZp7sNON/7uwFoTYkBa8f6eqf/QywVfoSFcvSC6GkyHD2TBwi1WPBQ07lGJHJrS86H5U5XMR8gPLUj4BpeSS736bsxsHKmF/N5nPQNxbfTXnhJc3lBEO++fXaSW6g5dAmX7F0iwauvjRrzVoECwT52e88j7vQKBgQC/9wHRHivZaebLuHiiyNHQorX+eP8dRoAys9lnSvyhkvqgkyx1uDf6+SaRplaGZhYYc6A1kpgIrZl8Vot/WkkiAYaGYHH1nFsM5B1CES8K4Jnnd4m+6KL1vpvTBai+ZKeFY0Hqp9Q190yM8fuRpDbHdhibZ9wGHdjpKp3xz9hsrwKBgQC2jCqKChppirgefdXtPYScPbqoaGTowX1m/HK2CuxByKNZQdK4GB/ASTKFhSj+8g86LcCEWdmzCvT5tY/uMRxbvvDuw7r4xlpzzh5kUuBStoUxo6+o5M0eh4Ulj2naRXzsmK7vKDC72By5KSI7zqWUga7H5nqzdKns5Bdd+8vrcwKBgQCcpsyjwzRTWpmN+77uUGTwFifgPwso78RkG+I46beZfuDpstBgTHHabAGucAhB6wLy90BxF2zcABa1ocZ6qcnuZ0JJXGEC5pJixbCennk+LiVJ/4G3+g4p7l8o6IBYxrjyIBrFjCmf1GxyxHHf2xsc0GGqSCoED81YEYAMuelKXwKBgGLU/GsEEUy29/w6MMpjFhrpKNfovUlvCI/recepnkP3dsjqZEWbegVHG/1CHPH659ed0a9WXhEbi4pujGBvYmUhuZvriJ0L9wjfvYCfhigB/ZbkgkQ0rAEtah7tyGeOW5ZVC9Ebt1bcKKDu7kPnG6qNk61S0Xe7YAyLaUNPAhaVAoGASI313bVoQgbKMCtW4TneIhlR+u5Z8X+8mRibjBpmWLI+vPup40C5hkXjGTyIWiiu+6lM+/mUho5QU7m3rMM8vndH7HATTwNhPrO2LKl8vLWD6OS2Bs1gxtiCXFvZ4uLjBLLWtvlVZGQV3Y05AB6KUW/bxdHq3Q9PGhYoqyZ2+SU=', // 支付宝私钥(1行填写)
                'notify_url'  => 'http://39.101.192.177/api/index/notifyurl', // 支付通知URL
            ]
        ];
        $pay = new \Pay\Pay($config);

        if ($pay->driver('alipay')->gateway()->verify($_POST)) {
            file_put_contents('notify.txt', "收到来自支付宝的异步通知\r\n", FILE_APPEND);
            file_put_contents('notify.txt', "订单单号：{$_POST['out_trade_no']}\r\n", FILE_APPEND);
            file_put_contents('notify.txt', "订单金额：{$_POST['total_amount']}\r\n\r\n", FILE_APPEND);
        } else {
            file_put_contents('notify.txt', "收到异步通知\r\n", FILE_APPEND);
        }
    }
    public function ali2(){
        $config = [
            // 微信支付参数
            'wechat' => [
                'app_id'     => '', // 应用ID
                'mch_id'     => '', // 微信支付商户号
                'mch_key'    => '', // 微信支付密钥
                'ssl_cer'    => '', // 微信证书 cert 文件
                'ssl_key'    => '', // 微信证书 key 文件
                'notify_url' => '', // 支付通知URL
            ],
            // 支付宝支付参数
            'alipay' => [
                'app_id'      => '2021001144613411', // 应用ID
                'public_key'  => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmfW7vg4fJTMeOHj3wHxSMqte662SYMy5Nrdx2N/QhcUaGxWWkeAlF/GshSN65mVcf7rM5SXo1XHDHzEwTEbRuQgprGncp+ZKCuLyegv8oVhmLX7gdlU3wx922GyNftv1gvRnWiVFOLIPS5yO8mc6N1niC874kO3mZyWTrO4h8OO1zmujWyv8uecVLO5niThiN2PX1K3WY7xt8VKGiuVHBrVg9OAyBacraKVYRY8Yz1BfaIgw8vzwhnyFyMwMBOoaYomPw1PSaVPX3hE68znRHUNhJarAS7jH682lVU/uOXjLfKB3FkK4O3Lew0gWgLoLgoHc1AUAxoY+bAyXOKyx/wIDAQAB', // 支付宝公钥(1行填写)
                'private_key' => 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCI4rZFstZqhlSujSt93Il62PyeKIgGhfciz+ia0G5RImZWWueCmQkkAxC/qEesWKm/aRfBxT97Ympdhlg4qwPRZSCqAkCMN7foTbefNeTny7Kc1QM8M7DxDavYzvCEjsrWriBT8HBtlT7IYzXbpsd+7VLq4V4TN40KVTouMPDsf211tnXotKbGKgnbVSqiiGBsxjpMFxlARUK9uV8vE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a9WXhEbi4pujGBvYmUhuZvriJ0L9wjfvYCfhigB/ZbkgkQ0rAEtah7tyGeOW5ZVC9Ebt1bcKKDu7kPnG6qNk61S0Xe7YAyLaUNPAhaVAoGASI313bVoQgbKMCtW4TneIhlR+u5Z8X+8mRibjBpmWLI+vPup40C5hkXjGTyIWiiu+6lM+/mUho5QU7m3rMM8vndH7HATTwNhPrO2LKl8vLWD6OS2Bs1gxtiCXFvZ4uLjBLLWtvlVZGQV3Y05AB6KUW/bxdHq3Q9PGhYoqyZ2+SU=', // 支付宝私钥(1行填写)
                // 'notify_url'  => 'http://39.101.192.177/api/index/notifyurl', // 支付通知URL
                'notify_url' => 'http://39.101.192.177/api/alindex/alipaynotifyurl',
            'return_url' => 'http://39.101.192.177/index/index/filish',
            ]
        ];
        // 实例支付对象
        $pay = new \Pay\Pay($config);
        $payData = [
//             "body"=>"对一笔交易的具体描述信息。如果是多种商品，请将商品描述字符串累加传给body。",
// "subject"=>"大乐透",
// "out_trade_no"=>"70501111111S001111119",
// "timeout_express"=>"90m",
// "total_amount"=>9.00,
// "product_code"=>"QUICK_WAP_WAY"
//   ];
            'body'         => '测试',
            'subject'      => 'test subject',
            'out_trade_no'     => 'test' . mt_rand(10000000,99999999).time(),// 自己实现生成
            // 'time_expire'  => time()+ '600', // 表示必须 600s 内付款
            'timeout_express'=>'90m',
            'total_amount'       => '0.01', // 微信沙箱模式，需要金额固定为3.01
            'return_param' => '123',
            'client_ip'    => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1', // 客户地址
        ];
        try {
            $options = $pay->driver('alipay')->gateway('wap')->apply($payData);
            echo $options;
        } catch (Exception $e) {
            echo "创建订单失败，" . $e->getMessage();
        }
    }
}
